/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package poker.geneticAlgorithm;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Benjamin L. Brodie <blbrodie@gmail.com>
 */
public class WeightsIndividual implements Individual<Double>{
    public List<Double> weightValues;
    
    public List<Double> getList() {
       return new ArrayList<Double>(weightValues);
    }
    
    /**
     * Generates a random individual.
     * @param length the length of the individual.
     */
    public WeightsIndividual(int length){
        if (length < 1){
            throw new IllegalArgumentException("lenght must be greater than 0");
        }
        
        weightValues = generateRandomValues(length);
    }
    
    /**
     * Generates a preset individual.
     * 
     * @param listOfWeights a list of weights to preset the individual.
     */
    public WeightsIndividual(List<Double> listOfWeights){
        if (listOfWeights == null){
            throw new IllegalArgumentException("A null list was passed.");
        }
        
        weightValues = new ArrayList<Double> (listOfWeights);
    }
    
    /**
     * Copies an individual.
     * 
     * @param individual the individual to be copied.
     */
    public WeightsIndividual(Individual<Double> individual){
        weightValues = new ArrayList<Double>(individual.getList());
    }

    
    private List<Double> generateRandomValues(int length){
        List<Double> values = new ArrayList<Double>(length);
        
        for (int i = 0; i < length; i++){
            values.add(Math.random() * 2 - 1);
        }
        
        return values;
        
    }
    
    @Override
    public String toString(){
        
        return weightValues.toString();
    }
}
